import $ from "jquery";
import {url} from "../../util/config";
import {message} from "antd";
import login from "../login";

function getNewLogin(values) {
    return judgeFolderAndArticle(values)
}
export default function judgeFolderAndArticle(values){
    if(values.parentType=="file"){
        values.parentType="file-d"
    }else if(values.parentType=="folder-f"){
        values.parentType="folder"
    }
    let token = localStorage.getItem("token")
    let frontResult = null;
    $.ajax({
        async:false,
        headers: {
            'Accept': "application/json",
            'Authorization': token
        },
        url: url.api_url+`judge/judgeResourceName?parentId=${values.parentId}&parentType=${values.parentType}&type=${values.type}&name=${values.value}`,
        type: 'get',
        success: function (result) {
            if(result.result=="Token過期請重新登錄"){
                login(localStorage.getItem("account"), localStorage.getItem("password"));
                frontResult = getNewLogin(values)
            }else {
                frontResult = result.conflict;
            }
        },
        error:function (error) {
            message.error("请求异常")
            frontResult = "网络异常"
        }
    })
    return frontResult;
}
